#ifndef MP4_CODEC_H
#define MP4_CODEC_H

#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/timeb.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/ipc.h>
#include <sys/socket.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/un.h>
#include <linux/videodev.h>
#include <linux/fb.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>

#include "utils.h"
#include "fmpeg4_avcodec.h"
#include "ratecontrol.h"


typedef struct YUVFrame {
    uint8_t *y;
    uint8_t *u;
    uint8_t *v;    
} YUVFrame;

typedef struct VideoEncoderProfile
{
	/* fixed part */
    uint32_t bit_rate;
    uint32_t width;   //length per dma buffer
    uint32_t height;
    uint32_t framerate;
    uint32_t frame_rate_base;
    uint32_t gop_size;
    uint32_t qmax;
    uint32_t qmin;   
    uint32_t quant;
    uint32_t u8NumComponents; // 3: YUV

	/* changable part */    
    uint32_t intra; // feedback to rate controll
    
    /* mpeg4 encoder variable*/
    int32_t             fmpeg4_enc_fd;       
    PacketQueue enc_queue; /* queue for mpeg4 encoder frame */   
    RateControl     ratec; /* rate control variable */
    
    /* fcap variable */
    int32_t             video_fd;
    struct video_mbuf       gb_mbuf; /* video buffer information */
    struct video_mmap       gb_mmap;  /* memory map address */
    uint8_t           *video_buf_virt; /* video capture buffer */   
    
} VideoEncoderProfile;

#define FB_PAGE_NUM 2

typedef struct FlcdData
{
    uint32_t buf_len;
    uint32_t uv_offset;
    uint32_t frame_no;
    uint32_t mp4_map_dma[FB_PAGE_NUM];
}FlcdData;


typedef struct VideoDecoderProfile
{
	/* fixed part */
    uint32_t bit_rate;
    uint32_t width;   //length per dma buffer
    uint32_t height;
    uint32_t framerate;
    uint32_t frame_rate_base;
    uint32_t gop_size;
    
    /* mpeg4 decoder variable*/
    int32_t         fmpeg4_dec_fd;  
    PacketQueue dec_queue; /* queue for mpeg4 decoder frame */        
    
    /* frame buffer variable */
    int32_t         fb_fd;
    FlcdData		f_data;
    YUVFrame		yuv_mmap[FB_PAGE_NUM]; // mmap_yuv[0]: blank screen; mmap_yuv[1]: real screen
    YUVFrame		yuv_dma[FB_PAGE_NUM]; // mmap_yuv[0]: blank screen; mmap_yuv[1]: real screen
    int32_t			yuv_len;
    int32_t			got_picture;
	
} VideoDecoderProfile;


#endif // MP4_CODEC_H
